package com.hotelmanage.hm.controller;

import com.hotelmanage.hm.service.RoomService;
import com.hotelmanage.hm.vo.RoomVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @RequestMapping("getAll")
    public Object getAll(){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("room",roomService.getAll());
        return map;
    }

    @RequestMapping("newRoom")
    public Object newRoom(@RequestBody RoomVO roomVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = roomService.newRoom(roomVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","新增失败");
        }else{
            map.put("status",200);
            map.put("desc","新增成功");
        }
        return map;
    }

    @RequestMapping("editRoom")
    public Object editRoom(@RequestBody RoomVO roomVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = roomService.editRoom(roomVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","编辑失败");
        }else{
            map.put("status",200);
            map.put("desc","编辑成功");
        }
        return map;
    }

    @RequestMapping("get")
    public Object get(@RequestParam Integer id){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("room",roomService.get(id));
        return map;
    }
}
